using System;
using System.Collections.Generic;
using System.Text;
using ChEngine;
using System.IO;
using System.Reflection;
using System.Diagnostics;


namespace FelpoEngine
{
    class Program
    {
        static WinBoardAdapter wba;
        
        static void Main(string[] args)
        {
            wba = new WinBoardAdapter(new ChessBoard());
            wba.MessageToWinboard += new EventHandler<EngineToWinboardEventArgs>(wba_MessageToWinboard);
            wba.EngineCreated += new EventHandler(wba_EngineCreated);
            do
            {
                string s = Console.ReadLine();
                wba.Consume(s);
                if (s == "quit")
                {
                    wba.Break();
                    break;
                }
            }
            while (true);
        }

        static void wba_EngineCreated(object sender, EventArgs e)
        {
            try
            {
                string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "felpobook.txt");
                FileStream fl = new FileStream(path, FileMode.Open);
                StreamReader sr = new StreamReader(fl);
                //PgnFileOpeningBook pgf = new PgnFileOpeningBook(sr,moveGenerator);
                sr.Close();
                fl.Close();
                //wba.Engine.OpeningBook = pgf;
            }
            catch(Exception ee)
            {
                Console.WriteLine(ee.Message);
            }
        }

        static void wba_MessageToWinboard(object sender, EngineToWinboardEventArgs e)
        {
            Console.WriteLine(e.Message);
        }
    }
}
